<?php

class Accomodation_model extends  Model {


    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }


    public function get_accomodation_list($limit,$start) {
        $accomodation_sql = "SELECT *
                                    FROM tbl_accomodations";
        $accomodation = $this->db->query($accomodation_sql);
         try{
            $accomodation_sql = "SELECT *
                                    FROM tbl_accomodations";
            $accomodation_sql.= " limit ".$start.",".$limit;
        $accomodation = $this->db->query($accomodation_sql);
        if($accomodation->num_rows() > 0) {
                 return $accomodation_result = $accomodation->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function get_accomodation_list_forhotelform() {
        $accomodation_sql = "SELECT *
                                    FROM tbl_accomodations";
        $accomodation = $this->db->query($accomodation_sql);
         try{
            $accomodation_sql = "SELECT *
                                    FROM tbl_accomodations";
        $accomodation = $this->db->query($accomodation_sql);
        if($accomodation->num_rows() > 0) {
                 return $accomodation_result = $accomodation->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function get_accomodation_list_count() {
         try{
            $accomodation_sql = "SELECT count(*) as count
                                    FROM tbl_accomodations";
        $accomodation = $this->db->query($accomodation_sql);
        if($accomodation->num_rows() > 0) {
                  $accomodation_result = $accomodation->row_array();
                  return $accomodation_result["count"];
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
        public function get_accomodation_list_forhoteledit($hotel_id) {

         try{
            $accomodation_sql = "SELECT *  ,  (select accid from tbl_hotelaccomodations b  where b.Hid={$hotel_id} and b.accid=a.id) as checkval FROM tbl_accomodations a
                                    
                       ";
        $accomodation = $this->db->query($accomodation_sql);
        if($accomodation->num_rows() > 0) {
                 return $accomodation_result = $accomodation->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }

     public function addnewaccomodation($acomdationdetails) {
        try{
                $accomodation_sql = "INSERT INTO tbl_accomodations
                                              (
                                               accdesc,
                                               status
                                              )
                                       VALUES (?,?)";
               $this->db->query($accomodation_sql, array(
                                             $acomdationdetails['txttitle'],
                                             $acomdationdetails['txtStatus'],

                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }

    public function get_accomodation_details($accid)
    {
        
         try{
           $accomodation_sql = "SELECT *
                                    FROM tbl_accomodations where id=?";
        $accomodation = $this->db->query($accomodation_sql, array($accid));
        if($accomodation->num_rows() > 0) {
                 return $accomodation_result = $accomodation->row_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
     public function doeditacomdation($acomdationdetails) {
      //   print_r($acomdationdetails);exit;
        try{
                $accomodation_sql = "update tbl_accomodations set accdesc=?,status=?  where id=?";
               $this->db->query($accomodation_sql, array(
                                             $acomdationdetails['txttitle'],
                                             $acomdationdetails['txtStatus'],
                                             $acomdationdetails['id']
                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }

      public function deleteacomdation($accid) {
      //   print_r($acomdationdetails);exit;
        try{
                $accomodation_sql = "delete from tbl_accomodations  where id=?";
               $this->db->query($accomodation_sql, array($accid
                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }

    /*public function get_featuredaccomodation_list() {
        /*$accomodation_sql = "SELECT *
                                    FROM tbl_featuredaccommodation";
        $accomodation = $this->db->query($accomodation_sql); * /
         try{
            $accomodation_sql = "SELECT *
                                    FROM tbl_featuredaccommodation";
        $accomodation = $this->db->query($accomodation_sql);
        if($accomodation->num_rows() > 0) {
                 return $accomodation_result = $accomodation->result_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }*/
    
    public function addnewfeaturedaccomodation($acomdationdetails) {
        try{            
            $accomodation_sql = "INSERT INTO tbl_featuredaccommodation
                                            (
                                            `title`,
                                            `desc`,
                                            `date_from`,
                                            `date_to`,
                                            `isactive`
                                            )
                                    VALUES (?,?,?,?,?)";
            $res=$this->db->query($accomodation_sql, array(
                                            $acomdationdetails['title'],
                                            $acomdationdetails['desc'],
                                            $acomdationdetails['date_from'],
                                            $acomdationdetails['date_to'],
                                            $acomdationdetails['isactive']

            ));

            $res2=$this->db->getLastInsertId();               
            $last_id=$res2->result_array();
            return ($last_id[0]['last_id']);
               

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function is_featured_accomodation_available()
    {        
         try{
           $accomodation_sql = "SELECT id
                                    FROM tbl_featuredaccommodation order by `id` desc limit 1";
        $accomodation = $this->db->query($accomodation_sql);
        if($accomodation->num_rows() > 0) {
                 return $accomodation_result = $accomodation->row_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
    public function get_featured_accomodation_details($featuredaccid)
    {
        
         try{
           $accomodation_sql = "SELECT *
                                    FROM tbl_featuredaccommodation where `id`=?";
        $accomodation = $this->db->query($accomodation_sql, array($featuredaccid));
        if($accomodation->num_rows() > 0) {
                 return $accomodation_result = $accomodation->row_array();
            } else {
                return FALSE;
            }
        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }
    
     public function doeditfeaturedacomdation($acomdationdetails) {
      //   print_r($acomdationdetails);exit;
        try{
                $accomodation_sql = "update tbl_featuredaccommodation set `title`=?,`desc`=?,`date_from`=?,`date_to`=?,`isactive`=?  where `id`=?";
               $this->db->query($accomodation_sql, array(
                                                        $acomdationdetails['title'],
                                                        $acomdationdetails['desc'],
                                                        $acomdationdetails['date_from'],
                                                        $acomdationdetails['date_to'],
                                                        $acomdationdetails['isactive'],
                                                        $acomdationdetails['id']
                ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }   
    
    /*public function deletefeaturedacomdation($faccid) {
      //   print_r($acomdationdetails);exit;
        try{
            $accomodation_sql = "delete from tbl_featuredaccommodation  where `id`=?";
            $this->db->query($accomodation_sql, array($faccid
            ));

        } catch(Exception $e){
            throw new Exception('Error in DB query');
            return FALSE;
        }
    }*/
    

}
?>
